package com.risk.web.controller.tk;

import com.risk.common.core.controller.BaseController;
import com.risk.common.core.domain.AjaxResult;
import com.risk.common.core.page.TableDataInfo;
import com.risk.common.utils.StringUtils;
import com.risk.kernel.domain.TkTaskCase;
import com.risk.kernel.service.TkTaskCaseServiceI;
import com.risk.kernel.vo.TkTaskCaseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liwen
 * @createTime: 2025/1/7
 * @description:
 */

@RestController
@RequestMapping("/tk/task/case")
public class TkTaskCaseController extends BaseController {

    @Autowired
    private TkTaskCaseServiceI tkTaskCaseService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('tk:case:list')")
    @GetMapping("/page/list")
    public TableDataInfo list(String keys) {
        startPage();
        List<TkTaskCaseVo> list = tkTaskCaseService.selectTkTaskCaseList(keys);
        return getDataTable(list);
    }


    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('tk:case:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tkTaskCaseService.selectTkTaskCaseById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('tk:case:add')")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody TkTaskCase tkTaskCase) {
        String userName = StringUtils.isEmpty(getNickName()) ? getUsername() : getNickName();
        tkTaskCase.setCreateBy(userName);
        return toAjax(tkTaskCaseService.insertTkTaskCase(tkTaskCase));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('tk:case:edit')")
    @PutMapping(value = "edit")
    public AjaxResult edit(@RequestBody TkTaskCase tkTaskCase) {
        String userName = StringUtils.isEmpty(getNickName()) ? getUsername() : getNickName();
        tkTaskCase.setUpdateBy(userName);
        return toAjax(tkTaskCaseService.updateTkTaskCase(tkTaskCase));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('tk:case:remove')")
    @DeleteMapping("/bathRemove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tkTaskCaseService.deleteTkTaskCaseByIds(ids));
    }




}
